﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using WindowsAPI;
namespace CSMDeamon
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            bool bExist = false;
            System.Threading.Mutex mm = new System.Threading.Mutex(true, "Mutex_CSMDeamon", out bExist);

            if (bExist)
            {
                Application.Run(new Form1());
                mm.ReleaseMutex();
            }
            else
            {
                //查找窗体
                IntPtr handle = WinAPI.FindWindow(null, "CSM进程守护者");
                if (handle != IntPtr.Zero)
                {
                    //恢复窗口并设置为前台窗口
                    WinAPI.SetForegroundWindow(handle);
                    WinAPI.OpenIcon(handle);
                }
            }

        }
    }
}
